package com.cl.security.core.entity;

import com.cl.security.base.entity.BaseEntity;
import com.cl.security.system.entity.FileInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "mall_product")
@Getter
@Setter
@SQLDelete(sql = "update mall_product set deleted=1 where id=?")
@Where(clause = "deleted<>1")
public class Product extends BaseEntity {
    @OneToOne(cascade = CascadeType.ALL,orphanRemoval = true)
    private FileInfo image;

    @OneToMany(mappedBy = "product")
    @JsonIgnoreProperties({"product"})
    private Set<PropertyValue> propertyValues = new HashSet<>();


    @OneToMany(mappedBy = "product",orphanRemoval = true,cascade = CascadeType.ALL)
    @JsonIgnoreProperties({"product"})
    private Set<Sku> skus = new HashSet<>();

    @ManyToOne
    @JsonIgnoreProperties({"products","children","parent"})
    @JoinColumn(name = "category_id",insertable = false,updatable = false)
    private Category category;

    @Column(name = "category_id")
    private Long categoryId;
}
